﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Common;

namespace TestLib.MockDBTools
{
    public class MockDbConnection:DbConnection
    {
        public MockDbConnection()
        {
            PState = System.Data.ConnectionState.Closed;
            PDatabase = "null";
        }

        protected override DbTransaction BeginDbTransaction(System.Data.IsolationLevel isolationLevel)
        {
            throw new NotImplementedException();
        }

        public override void ChangeDatabase(string databaseName)
        {
            if (PState!= System.Data.ConnectionState.Open)
            {
                throw new MockDbException("Connection is not yet opened!");

            }
            PDatabase = databaseName;
        }

        public override void Close()
        {
            PState = System.Data.ConnectionState.Closed;
        }

        public override string ConnectionString{get;set;}
        

        protected override DbCommand CreateDbCommand()
        {
            return new MockDbCommand(this);
        }

        public override void Open()
        {
            PState = System.Data.ConnectionState.Open;
        }

         string PDataSource{get; set;}
         string PDatabase{get;set;}
         string PServerVersion{get;set;}
        System.Data.ConnectionState PState{get;set;}

        public override string DataSource { get { return PDataSource; } }


        public override string Database { get { return PDataSource; } }

        public override string ServerVersion { get { return PServerVersion; } }
        public override System.Data.ConnectionState State { get { return PState; } }

    }
}
